﻿using EasyCore.Logging.Log4Net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyCore.Logging
{
    public static class LoggingExtensions
    {
        public static IServiceCollection AddMoreLogging(this IServiceCollection services)
        {
            services.AddLogging(builder =>
            {
                builder.ClearProviders();//清空日志提供器
                builder.AddProvider(new Log4NetLoggerProvider()); //添加日志提供器
            });
            return services;
        }

        /// <summary>
        /// 获得当前对象的日志器
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static ILogger<T> GetLogger<T>(this object obj)
        {
          var logger =  EasyCore.App.EasyApp.RequestService.GetService<ILogger<T>>();
            return logger;
        }


    }
}
